package com.zsix.system.strategy.formMenu;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Component
public class FormMenuContext {
    /**
     * 字典策略对象
     */
    private final List<FormMenuStrategy> formMenuStrategyList;
    /**
     * 构造函数
     * @param formMenuStrategies
     */
    public FormMenuContext(List<FormMenuStrategy> formMenuStrategies){
        this.formMenuStrategyList=formMenuStrategies;
    }
    /**
     * server容器
     */
    private Map<String, FormMenuStrategy> formMenuStrategyMap = new HashMap<>();

    /**
     * 初始化
     */
    @PostConstruct
    public void init(){
        formMenuStrategyMap=formMenuStrategyList.stream()
                .collect(Collectors.toMap(FormMenuStrategy::getType, o -> o));
    }
    /**
     * 获取方法
     * @param serviceType
     * @return
     */
    public FormMenuStrategy getService(String serviceType){
        return formMenuStrategyMap.get(serviceType);
    }
}
